<template>
  <view class="pay-page">
    <!-- 顶部栏 -->
    <view class="pay-header">
      <view class="title">付款码</view>
    </view>
    <!-- 支付码卡片 -->
    <view class="code-card">
      <view class="barcode-number">1305 4413 8579 408522</view>
      <image class="barcode" src="../../../assets/barcode.png" mode="widthFix" />
      <image class="qrcode" :src="qrImg" mode="aspectFit" />
      <view class="refresh-row">
        <text>刷新一下</text>
        <text class="refresh-icon">&#x21bb;</text>
      </view>
    </view>
    <!-- 去扫码付款按钮 -->
    <view class="scan-pay-btn" @click="scanCode()">
      <text class="scan-icon">▦</text>
      <text>去扫码付款</text>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { getQrcode } from '../../utils/api';

const qrImg = ref('');

onMounted(() => {
  
  // if(uni.getStorageSync('salesAmount')){
	 //  const salesAmount = uni.getStorageSync('salesAmount')
  // }else{
	 //  console.log("salesAmount还未存入")
  // }
  const salesAmount = uni.getStorageSync('salesAmount')
  
  if (!salesAmount || salesAmount.length > 6) {
    console.error('金额格式错误：salesAmount 必须为长度1-6的字符串');
    return;
  }

  const params = { 
	  salesAmount:String(salesAmount)
  };
  console.log(params)

  getQrcode(params).then(res => {
    console.log(res)
	qrImg.value = res.qrcodeUrl
  });
});

function scanCode(){
	uni.navigateTo({
	    url: '/pages/C/home/scan' // 替换为你的目标页面路径
	});
}
</script>

<style scoped src="./pay.css"></style>
